import React, { useEffect, useState } from 'react';
import { Select } from 'antd';
import { getChannels } from 'api/channel';
export default function Channel(props) {
  //   console.log(5, props);
  const [channels, setChannels] = useState([]);
  //   获取频道函数
  const getChannelList = async () => {
    const res = await getChannels();
    // console.log(res);
    setChannels(res.data.channels);
  };
  //   组件挂载时触发
  useEffect(() => {
    //   调用获取频道
    getChannelList();
  }, []);
  return (
    <Select placeholder="请选择频道" style={{ width: 200 }} {...props}>
      {channels.map((item) => (
        <Select.Option value={item.id} key={item.id}>
          {item.name}
        </Select.Option>
      ))}
    </Select>
  );
}
